Imports System.Collections

Partial Class pages_seriess_usercontrols_UCSeries : Inherits UserControl

#Region "Members"
    Private m_series As CSeries
    Private m_list As IList
#End Region

#Region "Interface"
    Public Sub Display(ByVal [series] As CSeries, list as IList)
        If Parent.Controls.Count Mod 2 = 0 Then row.Attributes.Add("class", "alt_row")

        m_series = [series]
        m_list = list

        With m_series
            chkNumber.Text = String.Concat(list.IndexOf(m_series) + 1, ".")
            chkNumber.Checked = CSession.SelectedSeriesIds.Contains(series.SeriesId)
            lnkSeriesName.Text =  CStr(IIF(.SeriesName.Length = 0, "...", .SeriesName))
            lnkSeriesName.NavigateUrl = CSitemap.SeriesEdit(.SeriesId)

            lnkData.Text = CUtilities.CountSummary(.Length, "day")
            lnkData.NavigateUrl = CSitemap.Datas(.SeriesId)
            litDp.Text = .SeriesDecimalPlaces.ToString()
            litPv.Text = .MeanPointValue.ToString("P4")

            If .Length > 0 Then
                litFrom.Text = .Datas.MinDate.ToString("d MMM yyyy")
                litTo.Text = .Datas.MaxDate.ToString("d MMM yyyy")

                litStart.Text = "$" & (CSimulation.START * CSimulation.LEVERAGE).ToString("n0")
                litSimTotal.Text = "$" & .Total.ToString("n2")
                litSimProfit.Text = "$" & .Profit.ToString("n2")
                litSimReturns.Text = .Returns.ToString("P2")
                litHigh.Text = "$" & .High.ToString("n0")
                litLow.Text = "$" & .Low.ToString("n0")
                If .AnnualisedReturns > 1000 Then
                    litAnnReturns.Text = (100 * .AnnualisedReturns).ToString("e1") & " %"
                Else
                    litAnnReturns.Text = .AnnualisedReturns.ToString("P2")
                End If
                litAvgExposure.Text = .AverageExposure.ToString("P2")
                litMaxExposure.Text = .MaxExposure.ToString("P2")
                If .ExposureAdjustedReturns > 1000 Then
                    litExpAdjReturns.Text = (100 * .ExposureAdjustedReturns).ToString("e1") & " %"
                Else
                    litExpAdjReturns.Text = .ExposureAdjustedReturns.ToString("P2")
                End If
                litWins.Text = .Datas.WinsPercent.ToString("P0")
                litLosses.Text = .Datas.LossesPercent.ToString("P0")
                litFlat.Text = .Datas.FlatPercent.ToString("P0")
                If .Returns < 0 Then litSimReturns.ForeColor = Drawing.Color.Red
                If .AnnualisedReturns < 0 Then litAnnReturns.ForeColor = Drawing.Color.Red
                If .ExposureAdjustedReturns < 0 Then litExpAdjReturns.ForeColor = Drawing.Color.Red
                If .Total < 0 Then litSimTotal.ForeColor = Drawing.Color.Red
                If .Profit < 0 Then litSimProfit.ForeColor = Drawing.Color.Red
            End If
        End With
    End Sub
#End Region

#Region "Event Handlers"
    Private Sub btnDelete_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btnDelete.Click
        m_series.Delete()

        CSession.SelectedSeriesIds.Remove(m_series.SeriesId)
        CSession.SelectedSeries = Nothing

        Refresh()
    End Sub
    Protected Sub chkNumber_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles chkNumber.CheckedChanged
        If chkNumber.Checked Then
            CSession.SelectedSeriesIds.Add(m_series.SeriesId)
        Else
            CSession.SelectedSeriesIds.Remove(m_series.SeriesId)
        End If
        Response.Redirect(Request.RawUrl)
    End Sub
#End Region

#Region "Private"
    Private Sub Refresh()
        'CCache.ClearCache()

        'If False Then 'Request.RawUrl.ToLower.Contains("myparent.aspx") Then
        '    'Special case: Parent entity owns the list
        '    Response.Redirect(CSitemap.MyParentEdit(m_series.SeriesParentId, MyParent.ETab.seriess, m_pageIndex)
        'Else
        '    'Normal case: Search page owns the list
            Response.Redirect(Request.RawUrl) 'includes paging info
        'End If 
    End Sub
#End Region

End Class
